<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>职员添加</title>
		<link rel="stylesheet" href="../layui/css/layui.css" media="all">
		<style>
			.empAddBox{
				margin: 0 auto;
				margin-top: 80px;
				border: solid gainsboro 1px;
				width: 80%;
				padding: 20px;
				height: 60%;
				
			}
		</style>
	</head>
	<body>
		<div class="empAddBox">
			<form class="layui-form layui-form-pane" method="post" action="">
				<div class="layui-form-item">
					<label class="layui-form-label">职员编号</label>
					<div class="layui-input-inline">
						<input type="text" id="employeeCode" name="employeeCode" lay-verify="required" placeholder="请输入职员编号" autocomplete="off"
						 class="layui-input">
					</div>
					<label class="layui-form-label">职员姓名</label>
					<div class="layui-input-inline">
						<input type="text" id="employeeName" name="employeeName" lay-verify="required" placeholder="请输入职员姓名" autocomplete="off"
						 class="layui-input">
					</div>
				</div>


				<div class="layui-form-item">
					<label class="layui-form-label">部门</label>
					<div class="layui-input-inline">
						<select id="department" name="department" lay-verify="required">
							<option value="">请选择部门</option>
							<option value="生产部">生产部</option>
							<option value="销售部">销售部</option>
							<option value="董事会">董事会</option>
						</select>
					</div>
					<label class="layui-form-label">职位</label>
					<div class="layui-input-inline">
						<select name="position" lay-verify="required">
							<option value="">请选择职位</option>
							<option value="总经理">总经理</option>
							<option value="职员">职员</option>
							<option value="老司机">老司机</option>
							<option value="总工">总工</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">生日</label>
						<div class="layui-input-inline">
							<input type="text" lay-verify="required" name="birthday" id="date1" placeholder="请选择日期" autocomplete="off" class="layui-input">
						</div>
						<label class="layui-form-label">性别</label>
						<div class="layui-input-inline">
							<input type="radio" name="gender" value="男" title="男" checked="">
							<input type="radio" name="gender" value="女" title="女">
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">状态</label>
					<div class="layui-input-block">
						<select name="state" lay-verify="required" lay-filter="aihao">
							<option value="">请选择状态</option>
							<option value="在公司">在公司</option>
							<option value="取货中">取货中</option>
							<option value="配送中">配送中</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<button type="submit" class="layui-btn" lay-submit="" lay-filter="demo222">确认修改</button>
				</div>
			</form>
			<input type="hidden" name="hidValue" id="hidValue" />
		</div>
		<script src="../layui/layui.js" charset="utf-8"></script>
		<script>
			layui.use(['form', 'laydate', 'jquery', 'table'], function() {
				var form = layui.form,
					layer = layui.layer,
					laydate = layui.laydate;
				var $ = layui.$;
				var empupdate = JSON.parse($("#hidValue").val());
				// 数据回显
				$("#employeeCode").val(empupdate.employeeCode);
				$("#employeeName").val(empupdate.employeeName);
				$("#date1").val(empupdate.birthday);
				// var department = empupdate.department
				// $("#department").val('生产部');
				// form.render('select'); //刷新select选择框渲染

				// alert(empupdate.department)
				// $(".selector").find("option[text='pxx']").attr("selected", true);
				// $("#department  option[value='生产部']").attr("selected", true);
				// $("#department").find("option[text='生产部']").attr("selected", "selected");
				// $("#department").next().find("dd[lay-value="+empupdate.department+"]").click();
				// $("#department").next().find('dd[lay-value=销售部]').click();
				// $("#department").val(empupdate.department);
				// form.render();
				//日期
				laydate.render({
					elem: '#date1'
				});

				//自定义验证规则
				form.verify({
					title: function(value) {
						if (value.length < 5) {
							return '标题至少得5个字符啊';
						}
					},
					content: function(value) {
						layedit.sync(editIndex);
					}
				});


				//监听提交
				form.on('submit(demo222)', function(data) {
						var index = parent.layer.getFrameIndex(window.name);
						$.ajax({
								url: 'http://localhost:9000/application/empUpdate',
								type: 'post',
								dataType: 'json',
								data: {
									"eiid": empupdate.eiid,
									"employeeCode": data.field.employeeCode,
									"employeeName": data.field.employeeName,
									"department": data.field.department,
									"position": data.field.position,
									"gender": data.field.gender,
									"birthday": data.field.birthday,
									"state": data.field.state,
								},
								success: function(data1) {
									if (data1.code == 0) {
										layer.msg(JSON.stringify(data1.msg), {

										});

										setTimeout(function() {
											parent.layer.close(index);
											parent.window.location.reload();
										}, 3000);
									} else {
										layer.msg("职员编号为：" + empupdate.eiid + "的职员信息更新失败", {

										});

									setTimeout(function() {
										window.location.href = "empwarning.html";
									}, 3000);
								}



							}
						});
						 return false;
				});



			//表单取值
			layui.$('#LAY-component-form-getval').on('click', function() {
				var data = form.val('example');
				alert(JSON.stringify(data));
			});

			});
		</script>

	</body>
</html>
